<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?=base_url()?>css/admin-bar.css" type="text/css" rel="stylesheet" />
<link href="<?=base_url()?>css/admin-menu.css" type="text/css" rel="stylesheet" />
<link href="<?=base_url()?>css/admin.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/demo_page.css" />
<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/demo_table_jui.css" />
<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/smoothness/jquery-ui-1.8.16.custom.css" />
<script type="text/javascript" src="<?=base_url()?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<?=base_url()?>ckfinder/ckfinder.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<?=$bar?>
<div id="main-content">
<?=$sidemenu?>
<script type="text/javascript">
	$('#sidemenu #post').addClass('current-top');
	$('#post-post').addClass('current');
	
	function warn(){
		var loaicha = $("#loaicha").val();
		//alert(loaicha);
		$.post("<?=base_url()?>index.php/qlsp_controller/getLoaiSPCon",{loaicha:loaicha},function(data){
			//alert(data);
			$('#loaicon').html(data);
		});
	}
	
</script>

<div id="content">
	<div id="content-head">
    	<h1>Sửa sản phẩm</h1>
    </div>
    <div id="content-body">

	<form action="<?=base_url()?>index.php/qlsp_controller/thuchiensua/<?=$sanpham[0]['MaSanPham']?>" method="post"  enctype="multipart/form-data">
    	<table width="800px" border="0">
		<tr>
			<td width="150px">
				<b>Thuộc chuyên mục:</b>
			</td>
			<td>
				<select name="loaicha" id="loaicha" onchange="warn();">
                	<option value="1">-----Tất cả-----</option>
					<?php
						foreach($dsspcha as $cha):
							if($chuyenmuccha == $cha['MaLoaiSP']){
								$select = "selected";
							}else{
								$select = "";
							}
							echo "<option value='$cha[MaLoaiSP]' $select>".$cha['TenLoaiSP']."</option>";
						endforeach;
					?>
                </select>
				<b style="padding-right:20px; padding-left:20px">Loại sản phẩm:</b>		
				 <span  name="loaicon" id="loaicon">
                    <select name="loaispcon" id="loaispcon">
	                    <option value="1">-----Tất cả-----</option>
                        <?php
						foreach($dsspcon as $con):
							if($chuyenmuccon == $con['MaLoaiSP']){
								$select = "selected";
							}else{
								$select = "";
							}
							echo "<option value='$con[MaLoaiSP]' $select>".$con['TenLoaiSP']."</option>";
						endforeach;
					?>
                    </select>
                 </span>
			</td>
		</tr>
		<tr>
			<td>
				<b>Tên:</b>
			</td>
			<td>
				<input size="60" name="ten" id="ten" value="<?=$sanpham[0]['TenSanPham']?>">
			</td>
		</tr>
		<tr>
			<td>
				<b>Hình ảnh: </b>	
			</td>
			<td>
				<input type="file" name="hinh_anh" size="40">
				<input type="hidden" name="link_anh" value="<?=$sanpham[0]['AnhSanPham'];?>" />
			</td>
		</tr>
		<tr>
			<td>
				<b>Giá bán: </b>	
			</td>
			<td>
				<input size="40" name="gia"  value="<?=$sanpham[0]['GiaBan']?>">&nbsp;&nbsp;&nbsp;(<i>Đơn vị:</i><b style="color:#F00">&nbsp;VNĐ</b>)
			</td>
		</tr>
		<tr>
			<td colspan="2"><br>
				<center><b>Mô tả sản phẩm:</b></center>
				
                <textarea cols="100" id="editor1" name="editor1" rows="10"><?=$sanpham[0]['MoTa']?></textarea>
				<center>
					<script type="text/javascript">
						var flag = true;
						var timer_start = false;
						var timer;
					//<![CDATA[
						// Replace the <textarea id="editor1"> with an CKEditor instance.
						var editor = CKEDITOR.replace( 'editor1', { enterMode		: 2, shiftEnterMode	: 2} );
						CKFinder.setupCKEditor( editor, '<?=base_url()?>ckfinder/' );
					//]]>
						CKEDITOR.instances.editor1.on('instanceReady',function(e){
							this.document.on("keyup", function() {
								
								if(timer_start == false) {
									timer_start = true;
									timer = setInterval(function(){
										$('#notice').text('Saving...');
										
										$.ajax({type:'post',
												url:'<?=base_url()?>index.php/qlsp_controller/autoSave',
												data :{data:CKEDITOR.instances.editor1.getData(),tensp:document.getElementById('ten').value},
												dataType: 'text',
												success: function(data){
													$('#notice').text('Saved');
													setTimeout(function(){
														$('#notice').text('');
													},1000);								
												}
											});

										if(flag) {
											flag=false;
										} else {
											clearInterval(timer);
											timer_start = false;
										}
									},5000);
								}
								flag = true;
							})
						})
					</script>
			  </center>
			</td>
		</tr>
		<tr>
			<td>&nbsp;
			  <input name="suasp" type="submit" value="Lưu lại" class="a-button">
			</td>
			<td align="right">
				<span id="notice" style="color:#FF0000; text-shadow: 5px 5px 5px #FF00FF;"></span>
			</td>
		</tr>
	</table>
	</form>
   
    </div>
</div>
</div>
</body>
</html>